<template>
	<a-card :bordered="false">
		<s-table
			ref="tableRef"
			:columns="columns"
			:data="loadData"
			:alert="options.alert.show"
			bordered
			:row-key="(record) => record.id"
			:tool-config="toolConfig"
			:row-selection="options.rowSelection"
		>
			<!-- eslint-disable-next-line vue/no-useless-template-attributes -->
			<template #bodyCell="{ column, record }">
				<template v-if="column.dataIndex === 'action'">
					<a-space>
						<a-space>
							<a-button type="link" size="small" @click="userListRef.showModal(record, record.groupId)"
								>查看成员</a-button
							>
						</a-space>
					</a-space>
				</template>
			</template>
		</s-table>
	</a-card>
	<UserList ref="userListRef" />
</template>

<script setup name="bizGroup">
	import UserList from '../userList/index.vue'
	import bizGroupApi from '@/api/biz/bizGroupApi'
	import { globalStore } from '@/store'
	const userListRef = ref()
	const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
	const columns = [
		{
			title: '社团名称',
			dataIndex: 'groupName',
			align: 'center'
		},
		{
			title: '管理员/创建人',
			dataIndex: 'applyName',
			align: 'center'
		}
	]
	// 操作栏通过权限判断是否显示
	if (hasPerm(['bizGroupEdit', 'bizGroupDelete'])) {
		columns.push({
			title: '操作',
			dataIndex: 'action',
			align: 'center',
			width: 400
		})
	}
	const selectedRowKeys = ref([])
	// 列表选择配置
	const options = {
		// columns数字类型字段加入 needTotal: true 可以勾选自动算账
		alert: {
			show: true,
			clear: () => {
				selectedRowKeys.value = ref([])
			}
		},
		rowSelection: {
			onChange: (selectedRowKey, selectedRows) => {
				selectedRowKeys.value = selectedRowKey
			}
		}
	}
	const loadData = (parameter) => {
		return bizGroupApi.bizGroupMyPage(parameter).then((data) => {
			console.log(data)
			return data
		})
	}
</script>
